import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, ManyToMany, JoinTable } from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { FeeMode, DifficultyLevel } from '../dto/create-activity.dto';

// 首先声明枚举，然后再使用它
export enum ActivityStatus {
  DRAFT = 'DRAFT',           // 草稿
  RECRUITING = 'RECRUITING', // 招募中
  FULL = 'FULL',             // 已满员
  ONGOING = 'ONGOING',       // 进行中
  COMPLETED = 'COMPLETED',   // 已完成
  CANCELLED = 'CANCELLED'    // 已取消
}

@Entity('activities')
export class Activity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column('text')
  description: string;

  @Column()
  type: string;

  @Column()
  startLocation: string;

  @Column()
  startAddress: string;

  @Column()
  endLocation: string;

  @Column()
  endAddress: string;

  @Column()
  startTime: Date;

  @Column()
  endTime: Date;

  @Column('text')
  routeDescription: string;

  @Column()
  maxParticipants: number;

  @Column()
  minParticipants: number;

  @Column()
  currentParticipants: number;

  @Column({
    type: 'enum',
    enum: FeeMode,
  })
  feeMode: FeeMode;

  @Column('decimal', { nullable: true })
  feeAmount: number;

  @Column('decimal', { nullable: true })
  depositAmount: number;

  @Column()
  feeDescription: string;

  @Column({
    type: 'enum',
    enum: DifficultyLevel,
  })
  difficultyLevel: DifficultyLevel;

  @Column()
  requirements: string;

  @Column()
  equipmentRequired: string;

  @Column({ name: 'view_count', default: 0 })
  viewCount: number;

  @Column({ name: 'favorite_count', default: 0 })
  favoriteCount: number;

  @Column({ name: 'comment_count', default: 0 })
  commentCount: number;

  @Column()
  cover: string;

  @Column({ nullable: true })
  tag: string;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'creatorId' })
  creator: User;

  @Column()
  creatorId: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @ManyToMany(() => User)
  @JoinTable({
    name: 'activity_participants', // 指定关联表名
    joinColumn: {
      name: 'activityId',
      referencedColumnName: 'id'
    },
    inverseJoinColumn: {
      name: 'userId',
      referencedColumnName: 'id'
    }
  })
  participants: User[];

  @Column({
    type: 'enum',
    enum: ActivityStatus,
    default: ActivityStatus.DRAFT
  })
  status: ActivityStatus;
}





